package com.cxy.mapper;

import com.cxy.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    /**
     * 计算数据库中记录的总数目
     * @return
     */
    @Select("select count(*) from emp")
    public Long countNum();

    /**
     * 展示的记录集合
     * @param pageSize
     * @param pageOffset
     * @return
     */
    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp limit #{pageSize} offset #{pageOffset}")
    public List<Emp> listSelect(@Param("pageSize") Integer pageSize, @Param("pageOffset") Integer pageOffset);

    /**
     * 通过使用PageHelper来进行分页查询
     * 只需要将数据全部信息查询，给与PageHelper的实例化对象
     */
    @Select("select * from emp")
    public List<Emp> list();

    public List<Emp> ifList(@Param("name") String name, @Param("gender")Short gender,@Param("begin") LocalDate begin, @Param("end")LocalDate end);

    public void deletebyIds(@Param("ids")List<Integer> ids);

    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    public void insert(Emp emp);

    @Select("select * from emp where id = #{id}")
    public Emp getById(Integer id);

    public void updateEmp(Emp emp);

    @Select("select * from emp where username = #{username} and password = #{password}")
     public Emp getByUsernameAndPassword(Emp emp);

    @Delete("delete from emp where dept_id = #{deptId}")
    public void deleteByDeptId(Integer deptId);
}
